//
//  CPYMVViewController.m
//  TTMusic
//
//  Created by chenpengyu on 16/4/8.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "CPYMVViewController.h"
#import "CPYMVTableViewCell.h"
#import "CPYMVModel.h"
#import "MVUrlModel.h"
#import "TTMusicAVPlayer.h"
#import "MJRefresh.h"
#import "UMSocial.h"
#import "YHY_MyPageMVViewController.h"
#import "YHY_DataBaseTool.h"

@interface CPYMVViewController ()<UITableViewDelegate, UITableViewDataSource, ButtonPlayActionDelegate, UMSocialUIDelegate>

@property (nonatomic, strong) TTMusicBaseTableView *playTableView;
@property (nonatomic, strong) AVPlayerItem *item;
@property (nonatomic, strong) NSMutableArray *dataSource;

@property (nonatomic, strong) NSMutableArray *urlArray;
@property (nonatomic, strong) NSMutableArray *textArray;
//@property (nonatomic, strong) NSMutableArray *shareText;

@property (nonatomic, strong) NSString *string;

@property (nonatomic, strong) NSString *urlString;

@property (nonatomic, strong) NSString *textString;

@property (nonatomic, strong) NSMutableArray *sendUrlArray;

@property (nonatomic, strong) CPYMVModel *model;

@property (nonatomic, strong) TTMusicBaseView *playView;

@property (nonatomic, assign)BOOL isplayer;

@property (nonatomic, assign)BOOL isplay;

@property (nonatomic, strong)UIButton *playClickbutton;

@property (nonatomic, strong)UISlider *slider;

@property (nonatomic, strong)NSTimer *sliderTime;

@property (nonatomic, strong)UILabel *timeLabel;

@property (nonatomic, strong)TTMusicBaseView *BtuClickView;

@property (nonatomic, strong)UIButton *plusButton;

//@property (nonatomic, strong)AVPlayerLayer *playerLayer;

@property (nonatomic, strong) TTMusicAVPlayer *moviePlayer;

@property (nonatomic, assign)BOOL isplus;

@property (nonatomic, assign) NSInteger row;

@property (nonatomic, assign) NSInteger page;

@property (nonatomic, assign) BOOL LOAD;

@property (nonatomic, strong) UIButton *loadButton;

@property (nonatomic, strong) UIButton *favoriteButton;

@property (nonatomic, strong) UIButton *shareButton;

@property (nonatomic, assign) BOOL isShare;

@property (nonatomic, assign) BOOL isHave;// 判断数据库中是否存在此页数据



@end

@implementation CPYMVViewController

- (void)viewWillAppear:(BOOL)animated {
    }

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    _isplay = YES;
//    _isShare = YES;
    [self creatView];
    self.dataSource = [NSMutableArray array];
    self.urlArray = [NSMutableArray array];
    self.sendUrlArray = [NSMutableArray array];
    self.textArray = [NSMutableArray array];
//    self.shareText = [NSMutableArray array];
//    [self dataRequest];
}


- (void)creatView {
    
    //自定义标题视图
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    titleLabel.text = @"MV";
    titleLabel.font = [UIFont boldSystemFontOfSize:25];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]  initWithTitle:@"< 返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
    
    // 创建tableView
    self.playTableView = [[TTMusicBaseTableView alloc] initWithFrame:CGRectMake(0, 0, SysWidth, SysHeight - 64) style:UITableViewStylePlain];
    [self.playTableView registerClass:[CPYMVTableViewCell class] forCellReuseIdentifier:@"CPYMVTableViewCellIdentifier"];
    self.playTableView.delegate = self;
    self.playTableView.dataSource = self;
    self.playTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.playTableView];
    
    // 刷新
    _LOAD = NO;
    
    self.page = 1;
    
    // 下拉刷新
    self.playTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        _LOAD = YES;
        
        [self dataRequest];
        
    }];
    
    [self.playTableView.mj_header beginRefreshing];
    
    // 上拉加载
    self.playTableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
        
        _LOAD = NO;
        
        self.page += 1;
        
        [self dataRequest];
        
    }];
    
    [self.playTableView.mj_footer beginRefreshing];
    
}
- (void)leftBarButtonAction:(UIBarButtonItem *)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"bottomViewNoHidden" object:nil];
    if ([self.item isEqual:nil]) {
        [[TTMusicAVPlayer shareTTMusicAVPlayer] pause];
    }else {
        
        [[TTMusicAVPlayer shareTTMusicAVPlayer] replaceCurrentItemWithPlayerItem:self.item];
        [[TTMusicAVPlayer shareTTMusicAVPlayer] play];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDelegate

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
    
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CPYMVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CPYMVTableViewCellIdentifier"];
    
    CPYMVModel *model = _dataSource[indexPath.row];
    
    self.textString = model.desc;
    
    MVUrlModel *mvModel = model.mvList[0];
    
    self.string = model.desc;

    
    cell.backgroundColor = COLOR(248, 249, 240);
    
    cell.mvModel = model;

    cell.urlModel = mvModel;
    
    
    self.urlString = mvModel.url;
    

    
    cell.delegate = self;
    cell.num = indexPath.row;
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return self.view.bounds.size.height * 0.45;;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (void)dataRequest {
    
    NSString *string = [NSString stringWithFormat:@"http://api.dongting.com/channel/channel/mvs?page=%ld&size=5&app=ttpod&v=v8.1.5.2016022418&user_id=0&mid=iPhone5C&f=f320&s=s310&imsi=&hid=&splus=9.2.1&active=1&net=2&openudid=72e56d97414e27ff046bb5997a15dd5f08a7b827&idfa=73524B41-B2E2-47A7-B7FD-F20ADEFBE5DA&utdid=VXknJXYlgCYDAA6KZBQ46nyN&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude=", self.page];
    
    [TTMusicAFNetworkTool GETNetWithUrl:string body:nil headerFile:nil response:TTMusicJSON success:^(id result) {
        
        for (NSDictionary *dic in result[@"data"]) {
            
            self.model  = [[CPYMVModel alloc] init];
            
            [_model setValuesForKeysWithDictionary:dic];
            
            [self.dataSource addObject:_model];
            
           }
        
        [self.playTableView reloadData];
        [self.playTableView.mj_footer endRefreshing];
        [self.playTableView.mj_header endRefreshing];
        
       

    } failure:^(NSError *error) {
        
    }];
    
}

#pragma mark - ButtonPlayActionDelegate (用代理方法把cell的坐标和URL传过来)

- (void)sendIndexthRow:(NSInteger)row WithUrl:(NSString *)url {
    
    
    // 判断是否有当前播放界面
    
    if (self.playView) {
        
        [self.playView removeFromSuperview];
        
        [self.moviePlayer pause];
        
    }
    
    // 创建播放界面
    self.playView =[[TTMusicBaseView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height * 0.45 * row, self.view.bounds.size.width, self.view.bounds.size.height * 0.45 * 0.8)];
    self.row = row;
    self.playView.backgroundColor = [UIColor blackColor];
    
    [self.playTableView addSubview:self.playView];

    
    
    // 创建播放
    self.moviePlayer = [TTMusicAVPlayer shareTTMusicAVPlayer];
    
    self.moviePlayer.playerLayer = [AVPlayerLayer playerLayerWithPlayer:_moviePlayer];
    
    self.moviePlayer.playerLayer.frame = self.playView.bounds;
    
    [self.playView.layer addSublayer:self.moviePlayer.playerLayer];
    
    
    self.item = [TTMusicAVPlayer shareTTMusicAVPlayer].currentItem;
    
    [_moviePlayer playWithMVURL:url];
    
    
    
    [self.moviePlayer play];

    

#pragma mark - 创建下载button
    self.loadButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_loadButton addTarget:self action:@selector(loadButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _loadButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.8 - 10, 20, 20);
    [_loadButton setImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
    [_playView addSubview:_loadButton];
    
#pragma mark - 创建收藏button
    
    self.model = _dataSource[self.row];
    
    self.favoriteButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    [_favoriteButton addTarget:self action:@selector(favoriteButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    _favoriteButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.7 - 10, 20, 20);
    
    _isHave = [[YHY_DataBaseTool shareDataBase] selectDataBase:self.model.bigPicUrl];
    
    if (_isHave == YES) {
        
        [_favoriteButton setImage:[UIImage imageNamed:@"VCLIke"] forState:UIControlStateNormal];
        _isShare = NO;
        
    }else {
        
        [_favoriteButton setImage:[UIImage imageNamed:@"1-1"] forState:UIControlStateNormal];
        _isShare = YES;
    }

    [_playView addSubview:_favoriteButton];
    
#pragma mark - 创建分享button
    self.shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    _shareButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.6 - 20, 20, 20);
    [_shareButton setImage:[UIImage imageNamed:@"fenxiang.png"] forState:UIControlStateNormal];
    [_playView addSubview:_shareButton];
    
#pragma mark - 创建放button和slider的View
    self.BtuClickView = [[TTMusicBaseView alloc]initWithFrame:CGRectMake(0, self.playView.bounds.size.height * 0.9, self.playView.bounds.size.width, self.playView.bounds.size.height * 0.1)];
    
    self.BtuClickView.backgroundColor = [UIColor blackColor];
    
    self.BtuClickView.alpha = 0.5;
    
    [self.playView addSubview:self.BtuClickView];
    
#pragma mark - 创建播放和暂停按钮
    
    self.playClickbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    [_playClickbutton addTarget:self action:@selector(clickbuttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.playClickbutton.frame = CGRectMake(5, 0, self.BtuClickView.frame.size.height, self.BtuClickView.frame.size.height);

    [self.playClickbutton setBackgroundImage:[UIImage imageNamed:@"VCStop"] forState:UIControlStateNormal];
    
    [self.BtuClickView addSubview: self.playClickbutton];
    
#pragma mark - 创建播放进度条
    
    // 创建slider
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(self.BtuClickView.frame.size.width * 0.1, 5, self.BtuClickView.frame.size.width * 0.5, self.BtuClickView.bounds.size.height - 10)];
//    self.slider.minimumTrackTintColor = [UIColor clearColor];
    self.slider.maximumTrackTintColor = [UIColor clearColor];
    
    _slider.minimumValue = 0.1;
    _slider.maximumValue = 1.0;
    
    // 添加事件
    [_slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.BtuClickView addSubview:_slider];
    
    
    self.moviePlayer.videoProgress.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.1, 5, self.BtuClickView.frame.size.width * 0.5, self.BtuClickView.bounds.size.height - 10);
    
    self.moviePlayer.videoProgress.trackTintColor = [UIColor yellowColor];
    self.moviePlayer.videoProgress.progressTintColor = [UIColor blueColor];
    
    self.moviePlayer.videoProgress.center = self.slider.center;
    
    [self.BtuClickView addSubview: self.moviePlayer.videoProgress];
    

    //创建定时器设置Slider
    _sliderTime = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(sliderTimeAction) userInfo:nil repeats:YES];
    
    // 创建timelabel来承接时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.BtuClickView.frame.size.width * 0.6, 0, self.BtuClickView.frame.size.width * 0.3, self.BtuClickView.frame.size.height)];
//    [self.BtuClickView addSubview:_timeLabel];
    
#pragma mark - 全屏button
    
    self.plusButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    _plusButton.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.9, 0, 26, 26);
    
    [_plusButton addTarget:self action:@selector(plusButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [_plusButton setImage:[UIImage imageNamed:@"plus"] forState:UIControlStateNormal];
    
    [self.BtuClickView addSubview:_plusButton];
    
    
    _isplus = YES;
    
}

#pragma mark - 下载
- (void)loadButtonAction:(UIButton *)sender {
    NSString *message = [NSString stringWithFormat:@"是否下载"];
    NSString *title = [NSString stringWithFormat:@"提示"];
    NSString *cancel = [NSString stringWithFormat:@"取消"];
    NSString *sure = [NSString stringWithFormat:@"确认"];
    
    //创建提示框
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    //确认按钮
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:sure style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        YHY_MyPageMVViewController *VC = [YHY_MyPageMVViewController shareMVPlayViewController];
        CPYMVModel *model = _dataSource[self.row];
        
        if (model.mvList.count != 0) {
            
            MVUrlModel *mvModel = model.mvList[0];
            
            if (![_urlArray containsObject:mvModel.url]) {
                
                [_urlArray addObject:mvModel.url];
                
                
                NSDictionary *dic = @{@"url":mvModel.url, @"title":model.desc};
                
                [_textArray addObject:dic];
                
                VC.textArray = _textArray;
                
                [[STLLoadMv sharedInstance] download:mvModel.url progress:^(CGFloat progress) {
                    
                } state:^(DownloadState DownloadStateStart) {
                    
                }];
            }else {
                
            }
        }
        else {
            [MBProgressHUD showAlertView:@"提示" andMessage:@"此MV暂不支持下载"];
        }
        
    }];
    
    //取消按钮
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [self presentViewController:alertController animated:YES completion:^{
        
    }];

    //添加按钮事件
    [alertController addAction:cancelAction];
    [alertController addAction:sureAction];
    
    
}

#pragma mark - 收藏

- (void)favoriteButtonAction:(UIButton *)sender {
    
    self.model = _dataSource[self.row];
    
    if (_isShare == YES) {
        
        
        _isHave = [[YHY_DataBaseTool shareDataBase] selectDataBase:self.model.bigPicUrl];
        
        if (_isHave == NO) {
            
            
            [[YHY_DataBaseTool shareDataBase] insertCPYMVModelIntoTable:self.model];
            
        }
        
        [_favoriteButton setImage:[UIImage imageNamed:@"VCLIke"] forState:UIControlStateNormal];
        
        _isShare = NO;
        
    }else {
        
        
         _isHave = [[YHY_DataBaseTool shareDataBase] selectDataBase:self.model.bigPicUrl];
        
        if (_isHave == YES) {
            
            [[YHY_DataBaseTool shareDataBase] deleteCPYMVModelTable:self.model.bigPicUrl];
            
        }
        
        [_favoriteButton setImage:[UIImage imageNamed:@"1-1"] forState:UIControlStateNormal];

        _isShare = YES;
        
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"shuaxin1" object:nil];
}

#pragma mark - 分享
- (void)shareButtonAction:(UIButton *)sender {
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"570656d8e0f55a98e0000ae9"
                                      shareText:self.string
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToRenren,UMShareToDouban,nil]
                                       delegate:self];
    
}

#pragma mark - 播放和暂停按钮点击事件
- (void)clickbuttonAction:(UIButton *)sender {
    
    if (_isplay == YES) {
        
        [self.moviePlayer pause];
        
        [self.playClickbutton setBackgroundImage:[UIImage imageNamed:@"VCPlay"] forState:UIControlStateNormal];
        
        _isplay = NO;
        
    }else {
        
        [self.moviePlayer play];
        
        [self.playClickbutton setBackgroundImage:[UIImage imageNamed:@"VCStop"] forState:UIControlStateNormal];
        
        _isplay = YES;
        
    }
}

#pragma mark - 播放进度条事件

- (void)sliderAction:(UIButton *)sender {
    
    //    跳转到的时间
    //    每秒多少帧
    if (self.moviePlayer.currentItem.duration.value ) {
        [self.moviePlayer seekToTime:CMTimeMakeWithSeconds(self.moviePlayer.currentItem.duration.value / self.moviePlayer.currentItem.duration.timescale * self.slider.value, self.moviePlayer.currentTime.timescale) completionHandler:^(BOOL finished) {
            
            [self.moviePlayer play];
            
        }];

    }
}

#pragma mark - 定时器与slider关联

- (void)sliderTimeAction {
    
    self.slider.value = CMTimeGetSeconds(self.moviePlayer.currentItem.currentTime) / CMTimeGetSeconds(self.moviePlayer.currentItem.duration);
    
#pragma mark - 创建时间
    
    CMTime presentTime = self.moviePlayer.currentItem.currentTime;
    
    CMTime totalTime = self.moviePlayer.currentItem.duration;
    
    CGFloat presentFloatTim = (CGFloat)presentTime.value/presentTime.timescale;
    CGFloat totalFloatTim = (CGFloat)totalTime.value / totalTime.timescale;
    
    self.slider.value = presentFloatTim / totalFloatTim;
    
    NSDate *presentDate = [NSDate dateWithTimeIntervalSince1970:presentFloatTim];
    
    NSDate *totalDate = [NSDate dateWithTimeIntervalSince1970:totalFloatTim];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    if (totalFloatTim / 3600 >= 1) {
        [formatter setDateFormat:@"HH:mm:ss"];
    }else {
        [formatter setDateFormat:@"mm:ss"];
    }
    
    NSString *presentStrTime = [formatter stringFromDate:presentDate];
    
    NSString *totalStrTime = [formatter stringFromDate:totalDate];
    
    NSString *string = [NSString stringWithFormat:@"%@/%@", presentStrTime, totalStrTime];
    
    self.timeLabel.text = string;
    
    self.timeLabel.textColor = [UIColor whiteColor];
    
    [self.BtuClickView addSubview:self.timeLabel];
}

- (NSString *)convertTime:(NSInteger)second {
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    
    NSDate *d = [NSDate dateWithTimeIntervalSince1970:second];
    if (second/3600 >= 1) {
        [fmt setDateFormat:@"HH:mm:ss"];
    } else {
        [fmt setDateFormat:@"mm:ss"];
    }
    
    NSString *showtimeNew = [fmt stringFromDate:d];
    return showtimeNew;
}

#pragma mark - plusButton点击事件
- (void)plusButtonAction:(UIButton *)sender {
    
    if (_isplus == YES) {
        
        self.navigationController.navigationBar.hidden  = YES;
        self.navigationController.navigationBar.translucent = YES;
        
        self.moviePlayer.videoProgress.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.1, 5, self.BtuClickView.frame.size.width * 0.5, self.BtuClickView.bounds.size.height - 10);
        
        self.moviePlayer.videoProgress.trackTintColor = [UIColor yellowColor];
        self.moviePlayer.videoProgress.progressTintColor = [UIColor blueColor];
        
//        self.moviePlayer.videoProgress.center = self.slider.center;
        

        self.playView.transform = CGAffineTransformMakeRotation(M_PI / 2);
        self.playView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        [self.view addSubview:_playView];
        self.moviePlayer.playerLayer.frame = _playView.bounds;
        self.BtuClickView.frame = CGRectMake(0, self.playView.bounds.size.height * 0.9, self.playView.bounds.size.width, self.playView.bounds.size.height * 0.1);
        self.slider.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.1, 0, self.BtuClickView.frame.size.width / 2 + 130, self.BtuClickView.frame.size.height);
        self.moviePlayer.videoProgress.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.1, 0, self.BtuClickView.frame.size.width / 2 + 130, self.BtuClickView.frame.size.height);
        self.moviePlayer.videoProgress.center = self.slider.center;

        self.timeLabel.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.78, 0, self.BtuClickView.frame.size.width * 0.15, self.BtuClickView.frame.size.height);
        self.playClickbutton.frame = CGRectMake(15, 2.5, self.BtuClickView.frame.size.height - 5, self.BtuClickView.frame.size.height - 5);
        self.plusButton.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.92, 0, self.BtuClickView.frame.size.height, self.BtuClickView.frame.size.height);
        [_plusButton setImage:[UIImage imageNamed:@"suoxiao "] forState:UIControlStateNormal];
        _loadButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.8 - 10, 20, 20);
        
        _favoriteButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.7 - 10, 20, 20);
        
        _shareButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.6 - 20, 20, 20);
        
        _isplus = NO;
    }else {
        
        self.navigationController.navigationBar.hidden = NO;
        self.navigationController.navigationBar.translucent = NO;
        
        
        
        self.playView.transform = CGAffineTransformIdentity;
        
        self.playView.frame= CGRectMake(0, self.view.bounds.size.height * 0.45 * self.row , self.view.bounds.size.width, self.view.bounds.size.height * 0.45 * 0.8);
        
        [self.playTableView addSubview:_playView];
        
        self.moviePlayer.playerLayer.frame = _playView.bounds;
        
        
        self.BtuClickView.frame = CGRectMake(0, self.playView.bounds.size.height * 0.9, self.playView.bounds.size.width, self.playView.bounds.size.height * 0.1);
        
        self.slider.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.1, 0, self.BtuClickView.frame.size.width * 0.5, self.BtuClickView.frame.size.height);
        
        self.moviePlayer.videoProgress.frame = self.slider.frame;
        self.moviePlayer.videoProgress.trackTintColor = [UIColor yellowColor];
        self.moviePlayer.videoProgress.progressTintColor = [UIColor blueColor];
        
        self.moviePlayer.videoProgress.center = self.slider.center;
        
        self.playClickbutton.frame = CGRectMake(5, 0, self.BtuClickView.frame.size.height, self.BtuClickView.frame.size.height);
        
        self.timeLabel.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.64, 0, self.BtuClickView.frame.size.width * 0.3, self.BtuClickView.frame.size.height);
        
        self.plusButton.frame = CGRectMake(self.BtuClickView.frame.size.width * 0.9, 0, self.BtuClickView.frame.size.height, self.BtuClickView.frame.size.height);
        [_plusButton setImage:[UIImage imageNamed:@"plus"] forState:UIControlStateNormal];

        _loadButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.8 - 10, 20, 20);
        
        _favoriteButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.7 - 10, 20, 20);
        
        _shareButton.frame = CGRectMake(self.playView.bounds.size.width - 40, self.playView.bounds.size.height * 0.6 - 20, 20, 20);
        
        _isplus = YES;

    }
    
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    if (_playTableView.contentOffset.y < 0 || _playTableView.contentOffset.y > _playTableView.bounds.size.height) {
//        [[TTMusicAVPlayer shareTTMusicAVPlayer] pause];;
//    }
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
